import { createRouter, createWebHistory } from 'vue-router';
import { showToast } from 'vant';
const router = createRouter({
        history: createWebHistory(),
        routes: [{
                path: '/',
                component: () =>
                    import ('../myHome/MyHome.vue')
            },
            {
                path: '/home',
                component: () =>
                    import ('../myHome/MyHome.vue'),

            },
            {
                path: '/cart',
                component: () =>
                    import ('../myCar/MyCar.vue'),
                meta: {
                    isaugth: true
                }
            },
            {
                path: '/order',
                component: () =>
                    import ('../myOrder/MyOrder.vue'),
                meta: {
                    isaugth: true
                }
            },
            {
                path: '/mine',
                component: () =>
                    import ('../Mine/Mine.vue'),
                meta: {
                    isaugth: true
                }
            },
            {
                path: '/store',
                component: () =>
                    import ('../store/MyStore.vue'),

            },
            {
                path: '/creatOrde',
                component: () =>
                    import ('../createOrde/createOrde.vue'),
                meta: {
                    isaugth: true
                }
            },
            {
                path: '/adress',
                component: () =>
                    import ('../adress/adress.vue'),
                meta: {
                    isaugth: true
                }
            },
            {
                path: '/earess',
                component: () =>
                    import ('../adress/components/arearess.vue'),
                meta: {
                    isaugth: true
                }
            },
            {
                path: '/login',
                component: () =>
                    import ('../login/Login.vue')
            },
            {
                path: '/register',
                component: () =>
                    import ('../login/register.vue')
            },
            {
                path: '/userinfoe',
                component: () =>
                    import ('../userInfoEdit/userInfoEdit.vue')
            }
        ]

    })
    // 路由前置，to:从哪来，from，next要去哪
router.beforeEach((to, from, next) => {
        if (to.meta.isaugth) {
            if (localStorage.isLogin == "1") {
                next()
            } else {
                showToast("请先登录")
                next({ path: '/login' })
            }
        } else {
            next()
        }
    })
    // 导出路由
export default router;